<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<table border="1" cellspacing="0" cellpadding="10px" id="table">
			<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>年龄</th>
				<th>家庭地址</th>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">女</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">男</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="" /></td>
				<td>张三</td>
				<td class="sex">女</td>
				<td>20</td>
				<td>福建省</td>
			</tr>
		</table>
		<input type="checkbox" name="" id="quanxuan" value="" onclick="xuan()" />全选
		<input type="checkbox" name='' id="quanxuannan" value="" onclick="xuannan()" />全选男
		<input type="checkbox" name='' id="quanxuannv" value="" onclick="xuannv()" />全选女
	</body>
	<script type="text/javascript">
		function xuan(){
			var quanxuan=document.getElementById('quanxuan').checked;
			console.log(quanxuan);
			var table=document.getElementById('table');
			var input=table.getElementsByTagName('input');
			console.log(input);
			for(var i=0;i<input.length;i++){
				input[i].checked=quanxuan;
			}
		}
		function xuannan(){
			var quanxuannan =document.getElementById('quanxuannan').checked;
			console.log(quanxuannan);
			var sex=document.getElementsByClassName('sex');
			console.log(sex);
			for(i=0;i<sex.length;i++){
				if(sex[i].innerText=='男'){
					var table=document.getElementById('table');
					var input=table.getElementsByTagName('input');
					input[i].checked=quanxuannan;
				}
			}
		}
		function xuannv(){
			var quanxuannv=document.getElementById('quanxuannv').checked;
			console.log(quanxuannv);
			var sex=document.getElementsByClassName('sex');
			console.log(sex);
			var table=document.getElementById('table');
			var input=table.getElementsByTagName('input');
			for(i=0;i<sex.length;i++){
				if(sex[i].innerText=='女'){
					input[i].checked=quanxuannv;
				}
			}
		}
	</script>
</html>
